<?php
/**
* 系统后台数据操作类
* * @author 邝达峰
* @date 2014-09-19
*/

class adminsModel extends dbModel {

	/**
	* 构造函数
	* @param:  NULL
	* @return: NULL
	* @access: public
	*/
	public function __construct(){}

	/**
	 * 后台操作记录日志
	 * @param string $type          操作类型
	 * @param string $module        操作模块
	 * @param string $remark        操作备注
	 * @return bool
	 * @access public
	 */
	public  function log($type='',$module='',$remark='')
	{
		if($module == 'treelist' || $_GET['action'] == 'treelist') {
			return '';
		}
		if(empty($type))
		{
			if($GLOBALS['pVars']['subtitle'])
			{
				$type = ($end = strpos($GLOBALS['pVars']['subtitle'],'-'))?substr($GLOBALS['pVars']['subtitle'],0,$end):$GLOBALS['pVars']['subtitle'];
			}
			elseif($GLOBALS['pVars']['menutitle'])
			{
				$type = ($end = strrchr($GLOBALS['pVars']['menutitle'],'>'))?substr($end,1):$GLOBALS['pVars']['menutitle'];
				$type = ($end = strpos($GLOBALS['pVars']['menutitle'],'-'))?substr($GLOBALS['pVars']['menutitle'],0,$end):$GLOBALS['pVars']['menutitle'];
			}
			else
			{
				$type = DB::select("select menuName CNT from menu where action = '{$_GET['action']}'",-1);
			}
		}
		$insert['type'] = $type;
		$insert['module'] = $module?$module:$_GET['action'];
		if(empty($remark) && ($mid = DB::select("select menuId CNT from menu where action = '{$_GET['action']}'",-1)))
		{
			$remark = DB::select('select menuName CNT from menu where menuId = '.substr($mid,0,3),-1).' > '.$type;
		}
		$insert['remark'] = $remark;
		$insert['url'] = $_SERVER['REQUEST_URI'];
		$insert['method'] = $_SERVER['REQUEST_METHOD'];
		$insert['dateline'] = time();
		$insert['checker'] = $_SESSION['ADMINID'];
		return DB::insert('system_log',$insert);
	}

	/**
	 * 通过用户名获取到用户信息
	 * @param string $strName  用户名
	 * @param int $intState  在职情况：1在职可登录，0离职不能登录
	 * @return array
	 * @access public
	 */
	public function getUserInfo($strName = '',$intState = 1)
	{
		if(!empty($strName))
		{
			$strSql = "select id as adminId,username,password,menuId, group_id from system where state = ".$intState." and username = '".trim($strName)."'";
			$arrData = DB::select($strSql);
			return $arrData;
		}
	}


	/**
	 * 通过id菜单信息
	 * @param string $strId 菜单ID
	 * @return array
	 * @access public
	 */
	public function getMenuById($strId = '',$isshow = 0)
	{
		if(!empty($strId) && !empty($isshow))
		{
			$strSql = 'select id,menuId,menuName,action,isShow from menu where menuId in ('.$strId.') and isshow = '.$isshow.' order by menuId asc';
			$arrData = DB::select($strSql);
			return $arrData;
		}
	}
	
	
	/**
	 * 通过菜单信息
	 * @param string $isshow 菜单是否显示
	 * @return array
	 * @access public
	 */
	public function getMenuData($isshow = 1)
	{
		 if(is_numeric($isshow)){
		   $strSql = 'select id,menuId,menuName,action,isShow from menu where  isshow = '.$isshow.' order by menuId asc';
		   $arrData = DB::select($strSql);
		 }
		 return $arrData;
		
	}


	/**
	 * 通过用户名获取到用户信息
	 * @param string $intId  用户名id
	 * @param int $intState  在职情况：1在职可登录，0离职不能登录
	 * @return array
	 * @access public
	 */
	public function getUserInfoById($intId = '',$intState = 1)
	{
		if(!empty($intId))
		{
			$strSql = "select id as adminId,fullName as name,username,password,menuId, group_id,state,inviteCode from system where state = ".$intState." and id = ".trim($intId);
			$arrData = DB::select($strSql);
			return $arrData;
		}
	}



	/**
	 * 获取信息审核原因
	 * @param string $strBusiness  业务名，对应theme.inc.php 里面的 MSG_TYPE_LIST 常量
	 * @param string $msgId 信息id
	 * @param int $limit 返回条数
	 * @return array
	 * @access public
	 */
	public function getSysCheckInfo($strBusiness='',$msgId = 0,$limit = 1)
	{
		if(!empty($strBusiness))
		{
			$msgType = Func::get_msg_type($strBusiness);
			if(!empty($msgType)){
				$intLimit = $limit?$limit:1;
				$strSql = "select shopid,msgType,msgId,checkInfo,rankInfo,checkState,checker,checkTime from system_check where msgType = ".$msgType." and msgId = ".$msgId." order by checkTime limit  ".$intLimit;
				$arrData = DB::select($strSql);
				return is_array($arrData)?$arrData:null;
			}
		}
	}
	
	
	/**
	 * 获取信息审核历史原因
	 * @param string $strBusiness  业务名，对应theme.inc.php 里面的 MSG_TYPE_LIST 常量
	 * @param string $msgId 信息id
	 * @param int $limit 返回条数
	 * @return array
	 * @access public
	 */
	public function getSysCheckLogs($strBusiness='',$msgId = 0,$limit = 20)
	{
		if(!empty($strBusiness))
		{
			$msgType = Func::get_msg_type($strBusiness);
			if(!empty($msgType)){
				$intLimit = $limit?$limit:20;
				$strSql = "select shopid,msgType,msgId,checkInfo,rankInfo,checkState,checker,checkTime from system_check_log where msgType = ".$msgType." and msgId = ".$msgId." order by checkTime desc limit  ".$intLimit;
				$arrData = DB::select($strSql);
				return is_array($arrData)?$arrData:null;
			}
		}
	}



}
?>